<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path;
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<title>教师代看课申请-云校通-教师</title>
<jsp:include page="/WEB-INF/page/common/_header.jsp"></jsp:include>
<script src="<%=basePath %>/js/picker.js"></script>
<script src="<%=basePath %>/js/select.js"></script>
<body ontouchstart id="tjjsqj" class="js-jf">
	<div class="weui_tab tab-bottom">
		<div class="weui-header bg-blue"> 
	  		<div class="weui-header-left"> <a onclick="back()" href="javascript:" class="icon icon-109 f-white">取消</a> </div>
	    	<h1 class="weui-header-title">教师代看课申请</h1>
	    </div>
		<div class="weui_tab_bd">
			<div class="weui_cells weui_cells_access mt0">
				<div class="weui_cell">
					<div class="weui_cell_hd">
						<label class="weui_label"><img src="<%=basePath %>/images/shoukelaoshi@3x.png" style="width:18%;"/> 授课老师</label>
					</div>
					<div class="weui_cell_bd weui_cell_primary">
						<input class="weui_input tr" value="${user.teacher.name }" readonly/>
					</div>
				</div>
				<div class="weui_cell weui_cell_select weui_select_after">
	                <div class="weui_cell_hd">
	                    <label class="weui_label"><img src="<%=basePath %>/images/yuanyin@3x.png" style="width:18%;"/> 原因</label>
	                </div>
	            </div>
				<div class="weui_cell">
	                <div class="weui_cell_bd weui_cell_primary">
	                    <textarea id="reason" class="weui_textarea" placeholder="请输入代看课事由" rows="3"></textarea>
	                </div>
	            </div>
	            
	       </div>
	        
	        <div class="weui_cells weui_cells_access tdk-item mt5">
				<div class="weui_cell xtbg-add-list-title">
					<div class="weui_cell_bd weui_cell_primary">
						<p class="f16 tdk-title">调代看课1</p>
					</div>
				</div>
				<div class="weui_cell weui_cell_select">
					<div class="weui_cell_hd">
						<label class="weui_label"><i class="icon icon-51 f20 f-blue"></i> <span class="tdk-key">时间</span></label>
					</div>
					<div class="weui_cell_bd weui_cell_primary">
						<input name="courseDateStr" class="weui_input weui_input-select courseDate tdk-value" placeholder="请选择" readonly>
					</div>
				</div>
				<div class="weui_cell weui_cell_select weui_select_after">
	                <div class="weui_cell_hd">
			         	<label class="weui_label"><img src="<%=basePath %>/images/nianji@3x.png" style="width:18%;"/> <span class="tdk-key">班级</span></label>
			        </div>
	                <div class="weui_cell_bd weui_cell_primary weui_cell_ft">
	                	请选择
	                </div>
	                <input name="classGrade" type="text" class="picker-input class-grade tdk-value" readonly/>
	            </div>
				<div class="weui_cell weui_cell_select weui_select_after">
	                <div class="weui_cell_hd">
	                    <label class="weui_label"><img src="<%=basePath %>/images/jieci@3x.png" style="width:18%;"/> <span class="tdk-key">节次</span></label>
	                </div>
	                <div class="weui_cell_bd weui_cell_primary weui_cell_ft">
	                	请选择
	                </div>
	                <input name="lesson" type="text" class="picker-input tdk-value lesson" readonly/>
	            </div>
	            <div class="weui_cell">
					<div class="weui_cell_hd">
						<label class="weui_label"><img src="<%=basePath %>/images/kecheng@3x.png" style="width:18%;"/> <span class="tdk-key">课程</span></label>
					</div>
					<div class="weui_cell_bd weui_cell_primary weui_cell_ft">
	                	请选择
	                </div>
	                <input name="subjectId" type="text" class="picker-input subjectId tdk-value" readonly/>
	                <input name="subjectName" class="tdk-value" type="hidden"/>
				</div>
				<div class="weui_cell weui_cell_select weui_select_after">
	                <div class="weui_cell_hd">
	                    <label class="weui_label"><img src="<%=basePath %>/images/jieci@3x.png" style="width:18%;"/> <span class="tdk-key">调代看课类型</span></label>
	                </div>
	                <div class="weui_cell_bd weui_cell_primary weui_cell_ft">
	                	请选择
	                </div>
	                <input name="optionType" type="text" class="picker-input tdk-value" readonly/>
	            </div>
				
				<div class="weui_cell weui_cell_select">
					<div class="weui_cell_hd">
						<label class="weui_label"><img src="<%=basePath %>/images/shoukelaoshi@3x.png" style="width:18%;"> <span class="tdk-key">调代看老师</span></label>
					</div>
					<div class="weui_cell_bd weui_cell_primary weui_cell_ft">
	                	<div class="searchbar_wrap">
	                		<div class="weui_search_bar">
	                			<form class="weui_search_outer">
	                				<div class="weui_search_inner">
	                					<i class="weui_icon_search"></i>
	                					<input type="search" class="weui_search_input" placeholder="请输入教师姓名">
	                					<i class="weui_icon_clear"></i>
	                				</div>
	                			</form>
	                		</div>
	                	</div>
						<div id="search-content" style="height: 100%; z-index: 10; transform-origin: 0px 0px 0px; opacity: 1; transform: scale(1, 1);">
					       <div class="sb-content" style="position:inherit;overflow:scroll;"></div>
					    </div>
					    <input type="hidden" name="exchangeTeacherId" class="tdk-value">
					    <input type="hidden" name="exchangeTeacherName">
	                </div>
				</div>
				
				<div class="weui_cell weui_cell_select exchange hide">
					<div class="weui_cell_hd">
						<label class="weui_label"><i class="icon icon-51 f20 f-blue"></i> <span class="tdk-key">调课时间</span></label>
					</div>
					<div class="weui_cell_bd weui_cell_primary weui_cell_ft">
						<input name="exchangeCourseDateStr" class="weui_input weui_input-select courseDate tdk-value" placeholder="请选择" readonly>
					</div>
				</div>
				<div class="weui_cell weui_cell_select exchange hide">
	                <div class="weui_cell_hd">
	                    <label class="weui_label"><img src="<%=basePath %>/images/jieci@3x.png" style="width:18%;"/> <span class="tdk-key">调课节次</span></label>
	                </div>
	                <div class="weui_cell_bd weui_cell_primary weui_cell_ft">
	                	请选择
	                </div>
	                <input name="exchangeLesson" type="text" class="picker-input lesson tdk-value" readonly/>
	            </div>
	            <div class="weui_cell weui_cell_select exchange hide">
					<div class="weui_cell_hd">
						<label class="weui_label"><img src="<%=basePath %>/images/kecheng@3x.png" style="width:18%;"/> <span class="tdk-key">调课课程</span></label>
					</div>
					<div class="weui_cell_bd weui_cell_primary weui_cell_ft">
	                	请选择
	                </div>
	                <input name="exchangeSubjectId" type="text" class="picker-input subjectId tdk-value" readonly/>
	                <input name="exchangeSubjectName" type="hidden"/>
				</div>
			</div>
			
			<div class="weui_cells weui_cells_access tdk-item mt5">
				<div class="weui_cell xtbg-add-list-title">
					<div class="weui_cell_bd weui_cell_primary">
						<p class="f16 tdk-title">调代看课2</p>
					</div>
				</div>
				<div class="weui_cell weui_cell_select">
					<div class="weui_cell_hd">
						<label class="weui_label"><i class="icon icon-51 f20 f-blue"></i> <span class="tdk-key">时间</span></label>
					</div>
					<div class="weui_cell_bd weui_cell_primary">
						<input name="courseDateStr" class="weui_input weui_input-select courseDate tdk-value" placeholder="请选择" readonly>
					</div>
				</div>
				<div class="weui_cell weui_cell_select weui_select_after">
	                <div class="weui_cell_hd">
			         	<label class="weui_label"><img src="<%=basePath %>/images/nianji@3x.png" style="width:18%;"/> <span class="tdk-key">班级</span></label>
			        </div>
	                <div class="weui_cell_bd weui_cell_primary weui_cell_ft">
	                	请选择
	                </div>
	                <input name="classGrade" type="text" class="picker-input class-grade tdk-value" readonly/>
	            </div>
				<div class="weui_cell weui_cell_select weui_select_after">
	                <div class="weui_cell_hd">
	                    <label class="weui_label"><img src="<%=basePath %>/images/jieci@3x.png" style="width:18%;"/> <span class="tdk-key">节次</span></label>
	                </div>
	                <div class="weui_cell_bd weui_cell_primary weui_cell_ft">
	                	请选择
	                </div>
	                <input name="lesson" type="text" class="picker-input tdk-value lesson" readonly/>
	            </div>
	            <div class="weui_cell">
					<div class="weui_cell_hd">
						<label class="weui_label"><img src="<%=basePath %>/images/kecheng@3x.png" style="width:18%;"/> <span class="tdk-key">课程</span></label>
					</div>
					<div class="weui_cell_bd weui_cell_primary weui_cell_ft">
	                	请选择
	                </div>
	                <input name="subjectId" type="text" class="picker-input subjectId tdk-value" readonly/>
	                <input name="subjectName" class="tdk-value" type="hidden"/>
				</div>
				<div class="weui_cell weui_cell_select weui_select_after">
	                <div class="weui_cell_hd">
	                    <label class="weui_label"><img src="<%=basePath %>/images/jieci@3x.png" style="width:18%;"/> <span class="tdk-key">调代看课类型</span></label>
	                </div>
	                <div class="weui_cell_bd weui_cell_primary weui_cell_ft">
	                	请选择
	                </div>
	                <input name="optionType" type="text" class="picker-input tdk-value" readonly/>
	            </div>
				
				<div class="weui_cell weui_cell_select">
					<div class="weui_cell_hd">
						<label class="weui_label"><img src="<%=basePath %>/images/shoukelaoshi@3x.png" style="width:18%;"> <span class="tdk-key">调代看老师</span></label>
					</div>
					<div class="weui_cell_bd weui_cell_primary weui_cell_ft">
	                	<div class="searchbar_wrap">
	                		<div class="weui_search_bar">
	                			<form class="weui_search_outer">
	                				<div class="weui_search_inner">
	                					<i class="weui_icon_search"></i>
	                					<input type="search" class="weui_search_input" placeholder="请输入教师姓名">
	                					<i class="weui_icon_clear"></i>
	                				</div>
	                			</form>
	                		</div>
	                	</div>
						<div id="search-content" style="height: 100%; z-index: 10; transform-origin: 0px 0px 0px; opacity: 1; transform: scale(1, 1);">
					       <div class="sb-content" style="position:inherit;overflow:scroll;"></div>
					    </div>
					    <input type="hidden" name="exchangeTeacherId" class="tdk-value">
					    <input type="hidden" name="exchangeTeacherName">
	                </div>
				</div>
				
				<div class="weui_cell weui_cell_select exchange hide">
					<div class="weui_cell_hd">
						<label class="weui_label"><i class="icon icon-51 f20 f-blue"></i> <span class="tdk-key">调课时间</span></label>
					</div>
					<div class="weui_cell_bd weui_cell_primary weui_cell_ft">
						<input name="exchangeCourseDateStr" class="weui_input weui_input-select courseDate tdk-value" placeholder="请选择" readonly>
					</div>
				</div>
				<div class="weui_cell weui_cell_select exchange hide">
	                <div class="weui_cell_hd">
	                    <label class="weui_label"><img src="<%=basePath %>/images/jieci@3x.png" style="width:18%;"/> <span class="tdk-key">调课节次</span></label>
	                </div>
	                <div class="weui_cell_bd weui_cell_primary weui_cell_ft">
	                	请选择
	                </div>
	                <input name="exchangeLesson" type="text" class="picker-input lesson tdk-value" readonly/>
	            </div>
	            <div class="weui_cell weui_cell_select exchange hide">
					<div class="weui_cell_hd">
						<label class="weui_label"><img src="<%=basePath %>/images/kecheng@3x.png" style="width:18%;"/> <span class="tdk-key">调课课程</span></label>
					</div>
					<div class="weui_cell_bd weui_cell_primary weui_cell_ft">
	                	请选择
	                </div>
	                <input name="exchangeSubjectId" type="text" class="picker-input subjectId tdk-value" readonly/>
	                <input name="exchangeSubjectName" type="hidden"/>
				</div>
			</div>
			
	       <div class="weui_btn_area" id="applySubmit">
		        <a href="javascript:" class="weui_btn bg-blue">提交申请</a>
		    </div>
		    <div style="margin-bottom: 55px;"></div>
		</div>
	</div>
	
	<!--弹窗-->
	<div class="hide_bd1"></div>
	<div class="hb_choose type2" style="top: 90px;width: 100%;left:0;">
		<div class="bj">
		</div>
	</div>
</body>
<jsp:include page="/WEB-INF/page/common/_footer.jsp"></jsp:include>
<script type="text/javascript">
$(function(){
   var nowDate = getTime(new Date(), 'yyyy-MM-dd');
   $(".courseDate").datetimePicker({title:"选择代看课时间",m:1,min:nowDate,max:'2050-10-01'});
   $("input[name='classGrade']").click(function() {
	    $(this).addClass("active").siblings().removeClass("active");
   		$(".type2").show();
		$(".hide_bd1").attr("style", "display: block;");
   })
   $(document).on("click", ".hb_choose .title>li", function(e) {
		$(this).addClass("active").siblings().removeClass("active");
		$(".yng").hide();
		$("#" + $(this).attr("data-key")).show();
   });
   $(document).on("click", ".list_3 .list_c3", function(e) {
		$(".picker-input.class-grade.active").val($(this).attr("data-value"));
		$(".picker-input.class-grade.active").closest(".weui_cell").find(".weui_cell_ft").text($(this).attr("data-name"));
		$(".picker-input.class-grade.active").removeClass("active");
		$(".type2").hide();
		$(".hide_bd1").attr("style", "display: none;");
   });
   
   $("input[name='optionType']").picker({
     title: "请选择",
     toolbarCloseText:'确定',
     onClose:function(){
     	$(this.input).closest(".weui_cell").find(".weui_cell_ft").text(this.cols[0].displayValue);
     	if(this.cols[0].value == '1') {
     		$(this.input).closest(".weui_cells").find(".exchange").removeClass("hide").addClass("exchangeShow");
     	}else {
     		$(this.input).closest(".weui_cells").find(".exchange").removeClass("exchangeShow").addClass("hide");
     	}
     },
     cols: [
       {
         textAlign: 'center',
         values: ['1','2','3'],
       	 displayValues: ['调课','代课','看课'],
       }
     ]
   });
   $(".lesson").picker({
     title: "请选择节次",
     toolbarCloseText:'确定',
     onClose:function(){
     	$(this.input).closest(".weui_cell").find(".weui_cell_ft").text(this.cols[0].displayValue);
     },
     cols: [
       {
         textAlign: 'center',
         values: ['上午第1节','上午第2节','上午第3节','上午第4节','下午第5节','下午第6节','下午第7节','晚修']
       }
     ]
   });
   
   $("#applySubmit").click(function(){
	   applySubmit();
   })
   //老师组织架构返回
   $("#teacherBack").click(function() {
		$('.ueureiu').hide();
		$("#ls_div_box").hide();
   });
   $(".weui_search_input").bind('input propertychange', function() {  
	   queryStudentItem($(this));
   });
   $(".weui_icon_clear").click(function() {
	    var parent = $(this).closest(".weui_cell_bd");
		parent.find(".weui_search_input").val(null);
		parent.find("input[name='exchangeTeacherId']").val(null);
		parent.find("input[name='exchangeTeacherName']").val(null);
   })
   loadClass();
   initSubjectList();
})
function applySubmit() {
	var reason = $("#reason").val();
	if(reason.length == 0) {
		$.alert("请输入调代看事由", "");
		return;
	}
	var itemTemplate = {
		courseDateStr: null,
		classGrade: null,
		lesson: null,
		subjectId: null,
		subjectName: null,
		optionType: null,
		exchangeTeacherId: null,
		exchangeTeacherName: null,
		exchangeCourseDateStr: null,
		exchangeLesson: null,
		exchangeSubjectId: null,
		exchangeSubjectName: null,
		hasChangeTeacher: 0
	}
	var paramList = [];
	var isOK = true;
	var itemList = $(".tdk-item");
	for(var i = 0; i < itemList.length; i++) {
		var v = $(itemList[i]);
		var list = v.find(".tdk-key");
		var itemObj = clone(itemTemplate);
		var tdkTitle = v.find(".tdk-title").html();
		for(var j = 0; j < list.length; j++){
			var v2 = $(list[j]);
			var parent = v2.closest(".weui_cell");
			var title = v2.html();
			var value = parent.find(".tdk-value").val();
			var name = parent.find(".tdk-value")[0].name;
			if(value == "" && name != 'exchangeTeacherId') {
				$.alert(tdkTitle+title+"不能为空");
				isOK = false;
				break;
			}
			itemObj[name] = value;
			if(name == 'subjectId' || name == 'exchangeTeacherId' || name == 'exchangeSubjectId') {
				itemObj[parent.find(".tdk-value").next()[0].name] = parent.find(".tdk-value").next().val();
				if(value.length > 0) {
					itemObj.hasChangeTeacher = 1;
				}
			}else if(name == 'optionType') {
				if(value == '1') {
					var exchangeList = v.find(".exchangeShow");
					for(var y = 0; y < exchangeList.length; y++){
						var v3 = $(exchangeList[y]);
						title = v3.find(".tdk-key").html();
						value =  v3.find(".tdk-value").val();
						name =  v3.find(".tdk-value")[0].name;
						if(value == "") {
							$.alert(tdkTitle+title+"不能为空");
							isOK = false;
							break;
						}
						itemObj[name] = value;
					}
				}
			}
		}
		if(!isOK) break;
		paramList.push(itemObj);
	}
	if(!isOK) return;
	var obj = {
		reason: reason,
		list: paramList
	}
	$.ajax({
   		url : basePath + "/ls/teacher/replace/course/publish/submit",
		type : "post",
		dataType : "json",
		headers: {
			'Accept': 'application/json',
			'Content-Type': "application/json"
		},
		data : JSON.stringify(obj),
	    success: function(data){
	    	if(data.code == '000') {
	    		$.toast("代看课申请提交成功！");
	    		var url = basePath + "/ls/teacher/replace/course?v=" + new Date().getTime();
	    		setTimeout("javascript:location.href='"+url+"'", 1000);
	    	}else {
	    		$.toptips(data.msg);
	    	}
	    },
	    error: function(xhr, type){
	      
	    }
	 });
}

function loadClass() {
	$.ajax({
   		url: basePath + "/classList",
   		type: 'POST',
   		dataType : "json",
   		success: function(data) {
   			if(data != null) {
   				var html = '<ul class="title">';
   				for(var i in data) {
   					var itm = data[i];
   					html += '<li class="'+(i == 0 ? "active " : "")+'" data-key="s'+itm.grade+'">'+itm.gradeText+'</li>';
   				}
   				html += "</ul>";
   				for(var i in data) {
   					var itm = data[i];
   					html += '<div class="yng" id="s'+itm.grade+'"><ul class="list_3">';
   					for(var j in itm.classList) {
   						var itm1 = itm.classList[j];
   						var gradeClass = itm1.grade + "-" + itm1.clazz;
   						html += '<li><div class="weui_cell_hd list_c3 f-green" data-value="'+gradeClass+'" data-name="'+itm.gradeText+"(" + itm1.clazz +"班)"+'">\
									'+itm1.clazz+'班\
								</div></li>';
   					}
   					html += '</ul></div>';
   				}
   				$(".bj").html(html);
   				$("#s" + data[0].grade).show();
   			}
   		},
   		error: function(data) {
   		}
   	});
}

function initSubjectList() {
	$.ajax({
 		url : basePath + "/subjectList",
 		type : "post",
 		dataType : "json",
 		async : false,
 		success : function(data) {
 			var values = [];
 			var displayValues = [];
 			for(var i in data){
 		        if (data.hasOwnProperty(i)) {
 		        	values.push(i);
 		        	displayValues.push(data[i])
 		        };
 		    }
 			$(".subjectId").picker({
		     title: "请选择学科",
		     toolbarCloseText:'确定',
		     onClose:function(){
		     	$(this.input).closest(".weui_cell").find(".weui_cell_ft").text(this.cols[0].displayValue);
		     	$(this.input).next().val(this.cols[0].displayValue);
		     },
		     cols: [
		       {
		         textAlign: 'center',
		         values: values,
		         displayValues: displayValues,
		       }
		     ]
		   });
 		}, error:function(){
 			
  		}
    });
}

var search = false;
function queryStudentItem(thiz) {
	keyword = thiz.val();
	if(keyword != null) {
		if(!/^[\u4E00-\u9FA5]+$/.test(keyword)) return;
		if(search) return;
		search = true;
	}
	$.ajax({
		url: basePath + "/ls/teacher/manage/keyword",
		type: 'POST',
		dataType : "json",
		data: {
			teacherName: keyword
		},
		success: function(data) {
			search = false;
			var html = "";
			if (data != null && data.length > 0) {
				for(var i in data) {
					var itm = data[i];
					html += '<div class="weui_cell"><p onclick=choseStudent(this,'+itm.id+',"'+itm.name+'")>'+ itm.name + '</p></div>';
				}
			}
			thiz.closest(".weui_cell_bd").find(".sb-content").html(html)
		},
		error: function(data) {
			$.alert("系统异常,请联系管理员","");
		}
	})
}
function choseStudent(thiz, studentId, studentName) {
	var parent = $(thiz).closest(".weui_cell_bd");
	parent.find(".weui_search_input").val(studentName);
	parent.find(".sb-content").html('');
	parent.find(".search-content").hide();
	parent.find("input[name='exchangeTeacherId']").val(studentId);
	parent.find("input[name='exchangeTeacherName']").val(studentName);
}
</script>
</html>